package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/2/27 15:04
 * @description
 */
public class Code754 {
    public static void main(String[] args) {
        System.out.println(new Code754().reachNumber(5));
    }

    public int reachNumber(int target) {
        target = Math.abs(target); //处理负值的情况
        int count = 0, sum = 0;
        while (sum < target) {
            count++;
            sum += count;
        }
        if ((sum - target) % 2 != 0) {
            count += (count % 2 == 0 ? 1 : 2);
        }
        return count;
    }
}
